//
//  CommonMallocLogger.h
//  QQLeakDemo
//
//  Tencent is pleased to support the open source community by making OOMDetector available.
//  Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
//  Licensed under the MIT License (the "License"); you may not use this file except
//  in compliance with the License. You may obtain a copy of the License at
//
//  http://opensource.org/licenses/MIT
//
//  Unless required by applicable law or agreed to in writing, software distributed under the
//  License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
//  either express or implied. See the License for the specific language governing permissions
//  and limitations under the License.
//
//

#import <Foundation/Foundation.h>
#import <malloc/malloc.h>
#import "CStackHelper.h"

#ifdef __cplusplus
extern "C" {
#endif
    extern malloc_zone_t *global_memory_zone;
    

//    stack_logging.h
//    malloc_logger(MALLOC_LOG_TYPE_ALLOCATE | MALLOC_LOG_TYPE_HAS_ZONE, (uintptr_t)zone, (uintptr_t)size, 0, (uintptr_t)ptr, 0);
//    #define MALLOC_LOG_TYPE_ALLOCATE stack_logging_type_alloc

//    #define stack_logging_type_free        0
//    #define stack_logging_type_generic    1    /* anything that is not allocation/deallocation */
//    #define stack_logging_type_alloc    2    /* malloc, realloc, etc... */
//    #define stack_logging_type_dealloc    4    /* free, realloc, etc... */
//    #define stack_logging_type_vm_allocate  16      /* vm_allocate or mmap */
//    #define stack_logging_type_vm_deallocate  32    /* vm_deallocate or munmap */
//    #define stack_logging_type_mapped_file_or_shared_mem    128
//
//    #define MALLOC_LOG_TYPE_HAS_ZONE stack_logging_flag_zone
//    #define    stack_logging_flag_zone        8    /* NSZoneMalloc, etc... */

    typedef void (malloc_logger_t)(uint32_t type, uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t result, uint32_t num_hot_frames_to_skip);
    
    extern malloc_logger_t* malloc_logger;
    
    void common_stack_logger(uint32_t type, uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t result, uint32_t backtrace_to_skip);
    
#ifdef __cplusplus
    }
#endif
